package com.yunxi.controller.sto;

import com.yunxi.bzToBase.service.StaffOrgInfoService;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoVehicleLendOrderQueryVO;
import com.yunxi.sto.pojo.StoVehicleLendOrderVO;
import com.yunxi.sto.service.StoVehicleLendOrderDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 借车单 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-30
 */
@RestController
@RequestMapping("/admin/stoVehicleLendOrder")
@Api(tags = "sto:vehicleLendOrder", description = "借车单接口")
public class StoVehicleLendOrderController {
 private static final Logger logger = LoggerFactory.getLogger(StoVehicleLendOrderController.class);

 @Autowired
 StoVehicleLendOrderDubboService stoVehicleLendOrderDubboService;

 @Autowired
 StaffOrgInfoService staffOrgInfoService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
 })
 public ApiResult page(StoVehicleLendOrderQueryVO stoVehicleLendOrderQueryVO, Integer pageNum, Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoVehicleLendOrderDubboService.findPageByVO(stoVehicleLendOrderQueryVO,pageNum,pageSize));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 @ApiImplicitParam(paramType="query", name = "lendOrderId", value = "主键id", required = true, dataType = "String")
 public ApiResult load(String lendOrderId, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoVehicleLendOrderDubboService.getById(lendOrderId));
 }

 @GetMapping("/loadDetail")
 @ApiOperation(value = "读取借车单详情")
 @ApiImplicitParam(paramType="query", name = "lendOrderId", value = "主键id", required = true, dataType = "String")
 public ApiResult loadDetail(String lendOrderId) throws Exception {
  return ResponseUtil.ok(stoVehicleLendOrderDubboService.loadDetail(lendOrderId));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoVehicleLendOrderVO stoVehicleLendOrderVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoVehicleLendOrderDubboService.saveOrUpdate(stoVehicleLendOrderVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/del")
 @ApiOperation(value = "作废")
 public ApiResult del(@RequestBody @ApiParam(value = "主键id集合")List<String>list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoVehicleLendOrderDubboService.delAndReset(list,1,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/reset")
 @ApiOperation(value = "恢复")
 public ApiResult reset(@RequestBody @ApiParam(value = "主键id集合")List<String>list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoVehicleLendOrderDubboService.delAndReset(list,0,loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @GetMapping("/orgList")
 @ApiOperation(value = "获取组织列表")
 public ApiResult orgList() throws Exception {
  List list = staffOrgInfoService.getOrgList();
  return ResponseUtil.ok(list);
 }

 @GetMapping("/staffList")
 @ApiOperation(value = "获取人员列表")
 @ApiImplicitParam(paramType="query", name = "orgId", value = "组织id", required = true, dataType = "String")
 public ApiResult staffList(String orgId) throws Exception {
  List list = staffOrgInfoService.getStaffById(orgId);
  return ResponseUtil.ok(list);
 }

 @GetMapping("/export")
 @ApiOperation(value = "导出")
 public ApiResult export(StoVehicleLendOrderQueryVO stoVehicleLendOrderQueryVO,@CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoVehicleLendOrderDubboService.export(stoVehicleLendOrderQueryVO));
 }

 /*@PostMapping("/outPlan")
 @ApiOperation(value = "转出库计划")
 public ApiResult outPlan(@RequestBody @ApiParam(value = "主键id集合")List<String>list) throws Exception {
  stoVehicleLendOrderDubboService.toInOutPlan(list,1);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/inPlan")
 @ApiOperation(value = "转入库计划")
 public ApiResult inPlan(@RequestBody @ApiParam(value = "主键id集合")List<String>list) throws Exception {
  stoVehicleLendOrderDubboService.toInOutPlan(list,0);
  return ResponseUtil.ok("success");
 }*/

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(stoVehicleLendOrderDubboService.findMapByList(params));
}*/
}
